package com.just.springbootmessage.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DelayMessageReceiver {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    private static final Logger logger=LoggerFactory.getLogger(DelayMessageReceiver.class);
    @RabbitListener(queues = "process-queue")
    public void receiver(String message){
        if("retry".equals(message)){
            logger.info("异常重试测试，收到的消息："+message);
            rabbitTemplate.convertAndSend("delay-queue","retry-ok");
        }else{
            logger.info("成功接收到消息："+message);
        }
    }
}
